<?php

namespace RjYst\ExcelExport;

use Illuminate\Support\ServiceProvider;

class RjExcelExportServiceProvider extends ServiceProvider
{
    /**
     * 注册服务
     */
    public function register()
    {
        // 合并配置文件
        $this->mergeConfigFrom(
            __DIR__.'/../config/rj-excel-export.php', 'rj-excel-export'
        );
    }

    /**
     * 启动服务
     */
    public function boot()
    {
        // 发布配置文件
        $this->publishes([
            __DIR__.'/../config/rj-excel-export.php' => config_path('rj-excel-export.php'),
        ], 'rj-excel-export-config');

        // 发布模板文件
        $this->publishes([
            __DIR__.'/Templates/CategorySheet.php' => app_path('Admin/Exports/Sheet/CategorySheet.php'),
            __DIR__.'/Templates/CategoryExport.php' => app_path('Admin/Exports/CategoryExport.php'),
            __DIR__.'/Templates/CategoryModuleSheet.php' => app_path('Admin/Exports/Sheet/CategoryModuleSheet.php'),
            __DIR__.'/Templates/CategoryModuleExport.php' => app_path('Admin/Exports/CategoryModuleExport.php'),
            __DIR__.'/Templates/ExcelExportController.php' => app_path('Admin/Controllers/Export/ExcelExportController.php'),
        ], 'rj-excel-export-templates');

        // 发布所有文件
        $this->publishes([
            __DIR__.'/../config/rj-excel-export.php' => config_path('rj-excel-export.php'),
            __DIR__.'/Templates/CategorySheet.php' => app_path('Admin/Exports/Sheet/CategorySheet.php'),
            __DIR__.'/Templates/CategoryExport.php' => app_path('Admin/Exports/CategoryExport.php'),
            __DIR__.'/Templates/CategoryModuleSheet.php' => app_path('Admin/Exports/Sheet/CategoryModuleSheet.php'),
            __DIR__.'/Templates/CategoryModuleExport.php' => app_path('Admin/Exports/CategoryModuleExport.php'),
            __DIR__.'/Templates/ExcelExportController.php' => app_path('Admin/Controllers/Export/ExcelExportController.php'),
        ], 'rj-excel-export-all');

        // 如果在控制台运行，注册命令
        if ($this->app->runningInConsole()) {
            $this->commands([
                \RjYst\ExcelExport\Console\Commands\InstallExcelExportCommand::class,
                \RjYst\ExcelExport\Console\Commands\UpdateExcelExportCommand::class,
            ]);
        }
    }
}
